package com.demo.wcx.greendaodemo;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2016-05-27.
 */
public class AddUserbeanActivity extends Activity {

    private EditText name, phone, sex;
    private TextView add;
    private DBHelper dbHelper;
    private UserBean userBean = new UserBean();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_userbean);

        dbHelper = DBHelper.getInstance(this);

        name = (EditText) findViewById(R.id.name);
        phone = (EditText) findViewById(R.id.phone);
        sex = (EditText) findViewById(R.id.sex);
        add = (TextView) findViewById(R.id.add);

        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(name.getText().toString().trim())) {
                    Toast.makeText(AddUserbeanActivity.this, "name can't be empty", Toast.LENGTH_SHORT)
                            .show();
                } else if (TextUtils.isEmpty(phone.getText().toString().trim())) {
                    Toast.makeText(AddUserbeanActivity.this, "phone can't be empty", Toast.LENGTH_SHORT)
                            .show();
                } else if (TextUtils.isEmpty(sex.getText().toString().trim())) {
                    Toast.makeText(AddUserbeanActivity.this, "sex can't be empty", Toast.LENGTH_SHORT).show();
                } else {
                    userBean.setName(name.getText().toString().trim());
                    userBean.setPhone(phone.getText().toString().trim());
                    userBean.setGender(sex.getText().toString().trim());

                    dbHelper.saveSession(userBean);
                    finish();
                }
            }
        });

    }
}
